package com.hspedu.codeblock;

/**
 * @Author Stringzhua
 * @Date 2024/3/5 18:59
 * description:分析运行结果
 * result:
 * s = 静态sam2成员初始化
 * static块执行
 * s = sam1成员初始化
 * Test默认构造器被调用
 */
public class CodeBlockExercise02 {
    public static void main(String[] args) {
        Test test = new Test();//类加载-->静态代码块初始化
    }
}

class Sample{
    Sample(String s){
        System.out.println("s = " + s);//01   -->05
    }
    Sample(){
        System.out.println("Sample默认构造函数被调用~");
    }
}

class Test{
    Sample sample1=new Sample("sam1成员初始化");//03
    static Sample sample2=new Sample("静态sam2成员初始化");//00
    static {
        System.out.println("static块执行");//02
        if(sample2==null){
            System.out.println("sample2 is null");
        }
    }
    Test(){
        System.out.println("Test默认构造器被调用");//06
    }
}


